// const {yy,usermodel,sortstore0a,token,comment,titlemodel,queschildstoremodel,modeldoitem} = require('../model/model');
const model = require('../model/model');
const mongoose = require('mongoose');

const basedao=require('../basedao')







class doitem extends basedao.basedao{

        /* 查询用户有没有做过指定题目 */
         findUserTittle(userid,tittleid){
          return  new Promise((res,rej)=>{
            this.model.aggregate(
                [
                    {
                        $match: { 'userid' : mongoose.Types.ObjectId(userid),'tittleid' : mongoose.Types.ObjectId(tittleid) }
                    },
              
       

                ],(err,docs)=>{

            
                    /* 如果，有记录，就返回true */
                             if(err||docs===[]||docs==={}||docs.length===0){res(false)}else if(docs!==[]||docs.lenth!==0) {res(docs)}
                        }
            )
          })    
        }

        /* 查询用户做过哪些题目 */
        finduserDo(userid){
          return  new Promise((res,rej)=>{
            this.model.aggregate(
                [
                    {
                        $match: { 'userid' : mongoose.Types.ObjectId(userid)}
                    },

                      {$lookup:{
                          from: "tittles",  
                          localField: "tittleid",  
                          foreignField: "_id",  
                          as: "tittles" 
                        }},

                        {$lookup:{
                            from: "profession",  
                            localField: "professionid",  
                            foreignField: "_id",  
                            as: "profession" 
                          }},

                          {$lookup:{
                              from: "kemu",  
                              localField: "kemuid",  
                              foreignField: "_id",  
                              as: "kemu" 
                            }},

                            {$lookup:{
                                from: "point",  
                                localField: "pointid",  
                                foreignField: "_id",  
                                as: "points" 
                              }},

                ],(err,docs)=>{
                             if(err||docs===[]||docs==={}||docs.length===0){res(false)}else if(docs!==[]||docs.lenth!==0) {res(docs)}
                        }
            )
          })  

        }


}





module.exports=doitem





